# -*- coding: utf-8 -*-
'''
@author: Lénia Andrade
'''
import sqlite3
from Collect_data import Collect_data

class Create_dataBase(object):
    '''
    classdocs
    '''


#    def __init__(selfparams):
#        '''
#        Constructor
#        '''

    def create_tables(self):
        '''
        criacao das tabelas da base de dados
        '''
        conn = sqlite3.connect('rebides.db')
        cursor = conn.cursor()
        cursor.execute("""CREATE TABLE IF NOT EXISTS grades 
                      (designation TEXT PRIMARY KEY)
                       """)
        cursor.execute("""CREATE TABLE IF NOT EXISTS courses
                      (designation TEXT PRIMARY KEY)
                       """)
        cursor.execute("""CREATE TABLE IF NOT EXISTS categories
                      (designation TEXT PRIMARY KEY)
                       """)
        cursor.execute("""CREATE TABLE IF NOT EXISTS regimes
                      (designation TEXT PRIMARY KEY)
                       """)
        cursor.execute("""CREATE TABLE IF NOT EXISTS estabelishments
                      (designation TEXT PRIMARY KEY)
                       """)
        cursor.execute("""CREATE TABLE IF NOT EXISTS estabelishment_types
                      (designation TEXT PRIMARY KEY)
                       """)
        cursor.execute("""CREATE TABLE IF NOT EXISTS teachers
                      (full_name TEXT PRIMARY KEY, 
                       code INTEGER UNIQUE)
                       """)
        cursor.execute("""CREATE TABLE IF NOT EXISTS fichas_curso
                      (id INTEGER PRIMARY KEY AUTOINCREMENT, 
                       year INTEGER,
                       teacher REFERENCES teachers (full_name),
                       grade REFERENCES graus (designation),
                       course REFERENCES cursos (designation))
                       """)
    
        cursor.execute("""CREATE TABLE IF NOT EXISTS fichas_docencia
                      (id INTEGER PRIMARY KEY AUTOINCREMENT, 
                       year INTEGER,
                       teacher REFERENCES docentes (full_name),
                       establishment REFERENCES establishments (designation),
                       category REFERENCES categories (designation),
                       regime REFERENCES regimes (designation),
                       estabelishment_types REFERENCES 
                       estabelishment_types (designation))
                       """)

        cursor.close()
        pass



    def preencher_tipos_estabelecimento(self, year):
        '''
        preenchimento da tabela tipos_estabelecimento
        '''
        self.year = year
        conn = sqlite3.connect('rebides.db')
        cursor = conn.cursor()
        print "ANO: 200{0}".format()
        d_establishment_types = Collect_data.get_type_of_establishment_codes(self.year)

        for Collect_data.type, Collect_data.codTypeEstablishment in d_establishment_types.iteritems():
            try:
                cmd = """insert into tipos_estabelecimento (designacao) values ('{0}')""".format(Collect_data.type)
                cursor.execute(cmd)
                conn.commit()
            except:
                pass
            pass
        cursor.close()
        pass
    
    
    

        
